import { PageRequest, PageData, FilterGroup } from '@/utils/common/types';

import { VxeTableDefines } from 'vxe-table';
import { propTypes } from '@/utils/propTypes';

import { basicProps } from '@/components/VxeTable/src/props';
import type { FormProps } from '@/components/Form';
import { FetchSetting } from '@/components/Table';

import { AdColumn } from './types/table';
import { SearchFormPropsType } from './types/searchForm';
import { DetailFormProps } from './types/detailForm';
import { FETCH_SETTING } from './const';

export const adVxeTableProps = {
  ...basicProps,
  /** 表格标题 */
  title: {
    type: [String, Function] as PropType<string | ((data: Recordable) => string)>,
    default: null,
  },
  /** 表格标题右侧提示信息 */
  helpMessage: {
    type: [String, Array] as PropType<string | string[]>,
  },
  /** 表格数据接口请求对象 */
  api: {
    type: Function as PropType<(params: PageRequest) => Promise<PageData | any>>,
    default: null,
  },
  /** 额外的搜索参数 */
  searchInfo: {
    type: Object as PropType<FilterGroup>,
    default: null,
  },
  /** 查询条件请求之前处理 */
  searchInfoFn: {
    type: Function as PropType<(info: FilterGroup) => Promise<FilterGroup>>,
    default: null,
  },
  /** 请求之前处理参数 */
  beforeFetch: {
    type: Function as PropType<Fn>,
    default: null,
  },
  /** 请求之后处理返回参数 */
  afterFetch: {
    type: Function as PropType<Fn>,
    default: null,
  },
  /** 请求配置 */
  fetchSetting: {
    type: Object as PropType<Partial<FetchSetting>>,
    default: () => {
      return FETCH_SETTING;
    },
  },
  /** 立即请求 */
  immediate: { type: Boolean, default: true },
  /** 在分页改变的时候清空选项 */
  clearSelectOnPageChange: propTypes.bool.def(true),
  /** 列配置 */
  columns: {
    type: Array as PropType<AdColumn[]>,
    default: () => [],
  },
  /** 是否显示序号列 */
  showSeqColumn: { type: Boolean, default: true },
  /** 序号列规则 */
  seqColumnRule: {
    type: String as PropType<'default' | 'page'>,
    default: 'page',
  },
  /** 序号列配置 */
  seqColumnProps: {
    type: Object as PropType<VxeTableDefines.ColumnOptions>,
    default: null,
  },
  /** 操作列配置 */
  actionColumn: {
    type: Object as PropType<VxeTableDefines.ColumnOptions>,
    default: null,
  },
  /** 点击行是否选中 checkbox 或者 radio */
  clickToSelect: { type: Boolean, default: true },
  /** 行选择类型 checkbox 或者 radio */
  selection: {
    type: String as PropType<'checkbox' | 'radio' | null>,
    default: null,
  },
  /** 选择列配置 */
  selectColumnProps: {
    type: Object as PropType<VxeTableDefines.ColumnOptions>,
    default: null,
  },
  /** 是否启用展开行 */
  expand: { type: Boolean, default: false },
  /** 展开列配置 */
  expandColumnProps: {
    type: Object as PropType<VxeTableDefines.ColumnOptions>,
    default: null,
  },
  /** 搜索表单 */
  searchForm: {
    type: [Object, Boolean] as PropType<SearchFormPropsType | boolean>,
    default: false,
  },
  /** 自定义表单 */
  customForm: {
    type: Object as PropType<Partial<FormProps>>,
    default: null,
  },
  /** 详情表单 */
  detailForm: {
    type: Object as PropType<DetailFormProps>,
    default: null,
  },
};
